class Solution {
public:
    bool isletter(char ch)
    {
        if('a' <= ch && ch <= 'z')
        {
            return true;
        }
        else if('A' <= ch && ch <= 'Z')
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    string reverseOnlyLetters(string s) 
    {
        int left = 0;
        int right = s.size()-1;
        while(left < right)
        {
            while(left < right && !isletter(s[left]))
            {
                left++;
            }
            while(left < right && !isletter(s[right]))
            {
                right--;
            }
            swap(s[left++],s[right--]);
        }
        return s;
    }
};